<?php

namespace app\admin\model\yalimedia;

use addons\shopro\library\notify\channel\Database;
use think\Db;
use think\Model;

class Teacher extends Model
{

    // 表名
    protected $name = 'yalimedia_teacher';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = "int";

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    // 追加属性
    protected $append = [
        'cate_text',
        'area_text',
    ];

    public function getCateTextAttr($val,$data){
        $cate = Db::table('fa_yalimedia_teacher_cate')->find($data['cate_id']);
        return $cate?$cate['name']:'';
    }

    public function getAreaTextAttr($val,$data){
        $ids = explode(',',$data['area_id']);
        $cate = Db::table('fa_city')->where('id','in',$ids)->select();
        $str = '';
        if($cate){
            $arr =  array_column($cate,'name');
            $str = implode(',',$arr);
        }

        return $str;
    }

}
